<template>
  <view class="help-center">
    <!-- 顶部导航栏 -->
    <view class="header">
      <view class="back-button" @click="handleBack">
        <view class="back-icon">
          <text>←</text>
        </view>
      </view>
      <view class="page-title">
        <span class="help-title-gradient">帮助中心</span>
      </view>
    </view>



    <!-- 主要内容区域 -->
    <view class="content-wrapper">
      <!-- 快捷入口 -->
      <view class="quick-links">
        <view class="section-title">
          <text>热门问题</text>
        </view>
        <view class="quick-links-grid">
          <view 
            class="quick-link-item"
            v-for="(item, index) in quickLinks" 
            :key="index"
            @click="scrollToSection(item.id)"
          >
            <view class="quick-link-icon">
              <uni-icons :type="item.icon" size="24" :color="item.color"></uni-icons>
            </view>
            <text class="quick-link-text">{{ item.title }}</text>
          </view>
        </view>
      </view>

      <!-- 帮助内容区域 -->
      <scroll-view class="help-content" scroll-y="true" scroll-with-animation="true" ref="helpContent">
        <!-- 新手入门 -->
        <view class="help-section" id="getting-started">
          <view class="section-header">
            <uni-icons type="star" size="20" color="#4CAF50"></uni-icons>
            <text class="section-title">新手入门</text>
          </view>
          <view class="section-content">
            <view class="help-item" v-for="(item, index) in gettingStartedItems" :key="index">
              <text class="help-item-title">{{ item.title }}</text>
              <text class="help-item-content">{{ item.content }}</text>
              <view class="help-item-divider"></view>
            </view>
          </view>
        </view>

        <!-- 功能介绍 -->
        <view class="help-section" id="features">
          <view class="section-header">
            <uni-icons type="apps" size="20" color="#2196F3"></uni-icons>
            <text class="section-title">功能介绍</text>
          </view>
          <view class="section-content">
            <view class="help-card" v-for="(feature, index) in features" :key="index">
              <view class="help-card-icon">
                <uni-icons :type="feature.icon" size="28" :color="feature.color"></uni-icons>
              </view>
              <view class="help-card-content">
                <text class="help-card-title">{{ feature.title }}</text>
                <text class="help-card-description">{{ feature.description }}</text>
              </view>
              <uni-icons type="right" size="20" color="#999"></uni-icons>
            </view>
          </view>
        </view>

        <!-- 使用教程 -->
        <view class="help-section" id="tutorials">
          <view class="section-header">
            <uni-icons type="book" size="20" color="#FF9800"></uni-icons>
            <text class="section-title">使用教程</text>
          </view>
          <view class="section-content">
            <view class="tutorial-item" v-for="(tutorial, index) in tutorials" :key="index">
              <view class="tutorial-image">
                <image :src="tutorial.image" mode="aspectFill"></image>
              </view>
              <view class="tutorial-info">
                <text class="tutorial-title">{{ tutorial.title }}</text>
                <text class="tutorial-duration">{{ tutorial.duration }}</text>
              </view>
              <uni-icons type="play-circle" size="24" color="#4CAF50"></uni-icons>
            </view>
          </view>
        </view>

        <!-- 常见问题 -->
        <view class="help-section" id="faq">
          <view class="section-header">
            <uni-icons type="question" size="20" color="#9C27B0"></uni-icons>
            <text class="section-title">常见问题</text>
          </view>
          <view class="section-content">
            <view class="faq-item" v-for="(faq, index) in faqs" :key="index">
              <view class="faq-question" @click="toggleFaq(index)">
                <text class="faq-question-text">{{ faq.question }}</text>
                <uni-icons 
                  :type="faq.expanded ? 'arrowup' : 'arrowdown'" 
                  size="18" 
                  color="#666"
                ></uni-icons>
              </view>
              <view class="faq-answer" :class="{ expanded: faq.expanded }">
                <text class="faq-answer-text">{{ faq.answer }}</text>
              </view>
            </view>
          </view>
        </view>

        <!-- 联系我们 -->
        <view class="help-section" id="contact">
          <view class="section-header">
            <uni-icons type="chatbubble" size="20" color="#F44336"></uni-icons>
            <text class="section-title">联系我们</text>
          </view>
          <view class="section-content">
            <view class="contact-info">
              <view class="contact-item">
                <uni-icons type="mail" size="20" color="#666"></uni-icons>
                <text class="contact-text">support@cloudkitchen.com</text>
              </view>
              <view class="contact-item">
                <uni-icons type="phone" size="20" color="#666"></uni-icons>
                <text class="contact-text">400-123-4567</text>
              </view>
              <view class="contact-item">
                <uni-icons type="time" size="20" color="#666"></uni-icons>
                <text class="contact-text">工作日 9:00-18:00</text>
              </view>
            </view>
            <button class="contact-button" @click="openFeedback">反馈问题</button>
          </view>
        </view>

        <!-- 版本信息 -->
        <view class="help-section version-info">
          <text class="version-text">CloudKitchen v1.0.0</text>
          <text class="copyright-text">© 2023 CloudKitchen. All rights reserved.</text>
        </view>
      </scroll-view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      currentSection: '',
      faqs: [
        {
          question: '如何注册账号？',
          answer: '在应用首页点击「注册」按钮，按照提示填写手机号码、验证码和密码即可完成注册。您也可以使用第三方账号（微信、QQ）快速登录。',
          expanded: false
        },
        {
          question: '如何发布我的第一个菜谱？',
          answer: '在底部导航栏点击「创建」按钮，进入菜谱创建页面，填写菜谱名称、描述、食材、步骤等信息，上传相关图片后点击「发布」即可。',
          expanded: false
        },
        {
          question: '如何收藏和点赞菜谱？',
          answer: '浏览菜谱详情页时，点击页面下方的心形图标可以收藏菜谱，点击点赞图标可以为菜谱点赞。您可以在个人中心查看所有收藏和点赞的菜谱。',
          expanded: false
        },
        {
          question: '如何关注其他用户？',
          answer: '在其他用户的个人主页点击「关注」按钮即可关注该用户。关注后，您可以在「关注」页面查看该用户发布的最新菜谱。',
          expanded: false
        }
      ],
      quickLinks: [
        { id: 'getting-started', title: '新手入门', icon: 'star', color: '#4CAF50' },
        { id: 'features', title: '功能介绍', icon: 'apps', color: '#2196F3' },
        { id: 'tutorials', title: '使用教程', icon: 'book', color: '#FF9800' },
        { id: 'faq', title: '常见问题', icon: 'question', color: '#9C27B0' }
      ],
      gettingStartedItems: [
        {
          title: '欢迎使用CloudKitchen',
          content: 'CloudKitchen是一个集菜谱分享、食材管理和烹饪社区于一体的综合平台。在这里，您可以发现美食、分享烹饪技巧、管理个人食材库存。'
        },
        {
          title: '主要功能概览',
          content: '- 浏览和搜索海量精选菜谱\n- 收藏和点赞喜欢的菜谱\n- 关注感兴趣的厨师和用户\n- 发布自己的创意菜谱\n- 管理个人食材库存\n- 参与烹饪社区讨论'
        },
        {
          title: '账号设置',
          content: '完善个人资料可以让其他用户更好地了解您。您可以上传头像、设置昵称、个人简介等信息。在个人中心页面点击「编辑资料」即可进行修改。'
        }
      ],
      features: [
        {
          title: '菜谱浏览',
          description: '分类浏览各种菜谱，按热度、时间、难度等多种方式筛选。',
          icon: 'image',
          color: '#E91E63'
        },
        {
          title: '食材管理',
          description: '记录家中现有的食材，系统会推荐适合的菜谱。',
          icon: 'basket',
          color: '#00BCD4'
        },
        {
          title: '社区互动',
          description: '关注其他用户，评论和点赞菜谱，分享烹饪心得。',
          icon: 'chatboxes',
          color: '#FFC107'
        },
        {
          title: '智能推荐',
          description: '根据您的口味偏好，智能推荐个性化菜谱。',
          icon: 'thumbsup',
          color: '#795548'
        }
      ],
      tutorials: [
        {
          title: '注册与登录教程',
          duration: '2:30',
          image: 'https://images.unsplash.com/photo-1611162617213-7d7a39e9b1d7'
        },
        {
          title: '发布高质量菜谱',
          duration: '5:45',
          image: 'https://images.unsplash.com/photo-1555396273-367ea4eb4dad'
        },
        {
          title: '食材管理技巧',
          duration: '3:20',
          image: 'https://images.unsplash.com/photo-1563245372-f21724e3856d'
        }
      ]
    }
  },
  methods: {
    // 返回上一页
    handleBack() {
      // 添加页面退出动画
      this.addPageExitAnimation(() => {
        uni.navigateBack();
      });
    },

    goBack() {
      uni.navigateBack()
    },

    scrollToSection(sectionId) {
      // 滚动到指定区域
      const query = uni.createSelectorQuery().in(this)
      query.select(`#${sectionId}`).boundingClientRect()
      query.exec(res => {
        if (res[0]) {
          const rect = res[0]
          const contentElement = this.$refs.helpContent
          if (contentElement) {
            // 直接设置滚动位置
            contentElement.scrollTop = rect.top - 100
          }
        }
      })
    },
    toggleFaq(index) {
      this.faqs[index].expanded = !this.faqs[index].expanded
    },
    openFeedback() {
      uni.navigateTo({
        url: '/pages/feedback/feedback'
      })
    },

    // 添加页面退出动画
    addPageExitAnimation(callback) {
      callback(); // 为简化示例，直接调用回调
    }
  }
}
</script>

<style lang="scss">
.help-center {
  min-height: 100vh;
  background-color: #f5f5f5;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;

  .header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
    padding: 0 20px;
    background-color: transparent;
    backdrop-filter: blur(10px);
    position: relative;
    z-index: 100;

    .back-button {
      width: 44px;
      height: 44px;
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 50%;
      cursor: pointer;
      transition: all 0.2s ease;

      &:active {
        background-color: rgba(0, 0, 0, 0.05);
      }

      .back-icon {
        width: 44px;
        height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #333;
        font-size: 24px;
        font-weight: 300;
      }
    }

    .page-title {
      font-size: 20px;
      font-weight: 700;
      margin-left: auto;
      
      .help-title-gradient {
        color: #ff6b6b;
      }
    }
  }

  .content-wrapper {
    padding: 16px;

    .quick-links {
      margin-bottom: 24px;

      .section-title {
        font-size: 16px;
        font-weight: 600;
        color: #333;
        margin-bottom: 12px;
        padding-left: 8px;
        border-left: 3px solid #ff6b6b;
      }

      .quick-links-grid {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 8px;

        .quick-link-item {
          display: flex;
          flex-direction: column;
          align-items: center;
          padding: 12px 4px;
          background-color: #fff;
          border-radius: 12px;
          box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
          transition: all 0.3s ease;

          &:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(255, 107, 107, 0.15);
          }

          .quick-link-icon {
            width: 36px;
            height: 36px;
            display: flex;
            align-items: center;
            justify-content: center;
            background-color: rgba(255, 107, 107, 0.1);
            border-radius: 18px;
            margin-bottom: 6px;
          }

          .quick-link-text {
            font-size: 11px;
            color: #333;
            text-align: center;
            line-height: 1.2;
          }
        }
      }
    }

    .help-content {
        height: calc(100vh - 180px);

      .help-section {
        margin-bottom: 24px;
        background-color: #fff;
        border-radius: 12px;
        overflow: hidden;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
        animation: fadeInUp 0.5s ease both;

        &:nth-child(1) { animation-delay: 0.1s; }
        &:nth-child(2) { animation-delay: 0.2s; }
        &:nth-child(3) { animation-delay: 0.3s; }
        &:nth-child(4) { animation-delay: 0.4s; }
        &:nth-child(5) { animation-delay: 0.5s; }

        .section-header {
          display: flex;
          align-items: center;
          gap: 8px;
          padding: 16px;
          background-color: #fafafa;
          border-bottom: 1px solid #f0f0f0;

          .section-title {
            font-size: 16px;
            font-weight: 600;
            color: #333;
          }
        }

        .section-content {
          padding: 16px;

          .help-item {
            margin-bottom: 16px;

            .help-item-title {
              font-size: 15px;
              font-weight: 600;
              color: #333;
              margin-bottom: 8px;
            }

            .help-item-content {
              font-size: 14px;
              color: #666;
              line-height: 1.6;
              white-space: pre-line;
            }

            .help-item-divider {
              height: 1px;
              background-color: #f0f0f0;
              margin-top: 16px;
            }
          }

          .help-card {
            display: flex;
            align-items: center;
            padding: 12px 0;
            border-bottom: 1px solid #f0f0f0;

            &:last-child {
              border-bottom: none;
            }

            .help-card-icon {
              width: 56px;
              height: 56px;
              display: flex;
              align-items: center;
              justify-content: center;
              background-color: #f5f5f5;
              border-radius: 8px;
              margin-right: 12px;
            }

            .help-card-content {
              flex: 1;
            }

            .help-card-title {
              font-size: 15px;
              font-weight: 600;
              color: #333;
              margin-bottom: 4px;
            }

            .help-card-description {
              font-size: 13px;
              color: #666;
              line-height: 1.5;
            }
          }

          .tutorial-item {
            display: flex;
            align-items: center;
            padding: 12px 0;
            border-bottom: 1px solid #f0f0f0;

            &:last-child {
              border-bottom: none;
            }

            .tutorial-image {
              width: 80px;
              height: 60px;
              border-radius: 8px;
              overflow: hidden;
              margin-right: 12px;
              position: relative;

              image {
                width: 100%;
                height: 100%;
                transition: transform 0.3s ease;
              }

              &:hover image {
                transform: scale(1.05);
              }
            }

            .tutorial-info {
              flex: 1;
            }

            .tutorial-title {
              font-size: 14px;
              font-weight: 500;
              color: #333;
              margin-bottom: 4px;
            }

            .tutorial-duration {
              font-size: 12px;
              color: #999;
            }
          }

          .faq-item {
            border-bottom: 1px solid #f0f0f0;

            &:last-child {
              border-bottom: none;
            }

            .faq-question {
              display: flex;
              justify-content: space-between;
              align-items: center;
              padding: 12px 0;
              cursor: pointer;
              transition: background-color 0.2s ease;

              &:hover {
                background-color: rgba(255, 107, 107, 0.02);
              }

              .faq-question-text {
                font-size: 14px;
                font-weight: 500;
                color: #333;
                flex: 1;
              }
            }

            .faq-answer {
              max-height: 0;
              overflow: hidden;
              transition: max-height 0.3s ease, padding 0.3s ease;

              &.expanded {
                max-height: 500px;
                padding-bottom: 12px;
              }

              .faq-answer-text {
                font-size: 13px;
                color: #666;
                line-height: 1.6;
              }
            }
          }

          .contact-info {
            margin-bottom: 16px;

            .contact-item {
              display: flex;
              align-items: center;
              gap: 12px;
              padding: 8px 0;

              .contact-text {
                font-size: 14px;
                color: #666;
              }
            }
          }

          .contact-button {
            width: 100%;
            height: 44px;
            background-color: #ff6b6b;
            color: #fff;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            font-weight: 500;
            transition: background-color 0.3s ease;

            &:hover {
              background-color: #ff5252;
            }
          }
        }

        &.version-info {
          text-align: center;
          padding: 24px 16px;
          background-color: transparent;
          box-shadow: none;

          .version-text {
            font-size: 14px;
            color: #666;
            margin-bottom: 8px;
          }

          .copyright-text {
            font-size: 12px;
            color: #999;
          }
        }
      }
    }
  }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
</style>